import 'package:shared_preferences/shared_preferences.dart';

class AsrLocalInfo {
  static SharedPreferences? sharedPreferences;

  static int? get userId => getUserId();

  static String? get token => getToken();

  static bool get isAgreePermission => getIsAgreePermission(); //是否同意用户协议

  static String? get message => getMessage();

  static Future<void> init() async {
    sharedPreferences = await SharedPreferences.getInstance();
  }

  // UserId
  static void setUserId(int id) {
    sharedPreferences?.setInt('userId', id);
  }

  static int? getUserId() {
    return sharedPreferences?.getInt('userId');
  }

  // Token
  static void setToken(String token) {
    sharedPreferences?.setString('token', token);
  }

  static String? getToken() {
    return sharedPreferences?.getString('token');
  }

  // message
  static void setMessage(String time) {
    sharedPreferences?.setString('message', time);
  }

  static String? getMessage() {
    return sharedPreferences?.getString('time');
  }

  static setIsAgreePermission() {
    sharedPreferences?.setBool('is_agree_permission', true);
  }

  static bool getIsAgreePermission() {
    return sharedPreferences?.getBool('is_agree_permission') ?? false;
  }

  static bool getMyState() {
    return sharedPreferences?.getBool('my_state') ?? true;
  }

  static setMyState(bool value) {
    sharedPreferences?.setBool('my_state', value);
  }

  // 清除登陆状态
  static void clearLoginStatus() {
    sharedPreferences?.remove('userId');
    sharedPreferences?.remove('token');
  }
}
